package com.zonekey.config;

import com.zonekey.service.impl.UserDetailServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @description:
 * @author: 靳俊英
 * @create: 2021-05-18 14:22
 **/
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    private UserDetailServiceImpl userDetailService;

    /**
     * 因为我们用密码授权不需要登录了，它内部就需要一个认证管理器
     * @return
     * @throws Exception
     */
    @Override
    @Bean
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
       auth.inMemoryAuthentication().withUser("test").password(passwordEncoder.encode("123456")).authorities("admin");
        auth.inMemoryAuthentication().withUser("jjy1").password(passwordEncoder.encode("123456")).authorities("admin");
        /*auth.userDetailsService(userDetailService);*/

    }


    /**
     *  添加资源服务器后，在资源服务种去过滤http, ResourceServerConfig
     */
/*    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.formLogin();
        http.authorizeRequests().anyRequest().authenticated();

    }*/
}
